<?php
$this->jQuery()->enable();
$this->headLink()
        ->appendStylesheet($this->baseUrl('/lib/flexigrid-1.1/css/flexigrid.css'))
        ->appendStylesheet($this->baseUrl('/lib/flexigrid-1.1/css/flexigrid-custom.css'));
$this->headScript()
        ->appendFile($this->baseUrl('/lib/flexigrid-1.1/js/flexigrid.js'));
?>

<table class='Oanhnn' style="display:none"></table>

<script type="text/javascript">
    <!--
    $(document).ready(function(){
        
        $('.Oanhnn').flexigrid({
            url : '/QLTSv1/front/test/records',
            dataType : 'json',
            colModel : [ 
                {display: 'Ma tai san', name: 'Ma_tai_san', width: 60, sortable: true, align: 'left'},
                {display: 'UserID', name: 'UserID', width: 50, sortable: true, align: 'left'},
                {display: 'Detail', name: 'Detail', width: 350, sortable: false, align: 'left'},
                {display: 'Date', name: 'Date', width: 70, sortable: true, align: 'left'}
            ],
            buttons : [ 
                {name : 'Add', bclass : 'add', onpress : add_record},
                {name : 'Edit', bclass : 'edit', opress : edit_record},
                {name : 'Delete', bclass : 'delete', onpress : delete_record}, 
                {separator : true} 
            ],
            searchitems : [ 
                {display : 'Ma tai san', name : 'Ma_tai_san', isdefault : true },
                {display : 'User ID', name : 'UserID' } 
            ],
            sortname : "Ma_tai_san",
            sortorder : "asc",
            usepager : true,
            title : 'Loan Table',
            useRp : true,
            rp : 15,
            showTableToggleBtn : true,
            width : 700,
            height : 200
        });

        function test(com, grid) {
            if (com == 'Delete') {
                confirm('Delete ' + $('.trSelected', grid).length + ' items?')
            } else if (com == 'Add') {
                alert('Add New Item');
            }
        }
        
        function add_record() { window.location='/front/test/add'; }
    
        function delete_record(command,grid)
        {
            var record_count = $('.trSelected',grid).length;
            if (0 == record_count)
            {
                alert('Please select a record first by clicking on the appropriate row.');
                return;
            }
            $('.trSelected',grid).each(function(){
                var id = this.id.substr(3);
                window.location = '/user/delete/id/'+id;
            });
        } // delete_record

        function edit_record(command,grid)
        {
            var record_count = $('.trSelected',grid).length;
            if (0 == record_count)
            {
                alert('Select a record first by clicking on the appropriate row.');
                return;
            }
            $('.trSelected',grid).each(function(){
                var id = this.id.substr(3);
                window.location = '/user/edit/id/'+id;
            });
        } // edit_record
    });
    -->
</script>

